-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add encodeUriComponent to file name #967
Conversation
Fix for non standard file names (with spaces, apostrophes, etc) that prevent to be used.
src/components/widgets/FileWidget.js
Outdated
@@ -4,6 +4,7 @@ import PropTypes from "prop-types"; | |||
import { dataURItoBlob, shouldRender, setState } from "../../utils"; | |||
|
|||
function addNameToDataURL(dataURL, name) { | |||
name=encodeURIComponent(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you've got a lint error here.
Do this instead:
function addNameToDataURL(dataURL, name) {
return dataURL.replace(";base64", `;name=${encodeURIComponent(name)};base64`);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @graingert, did not see your comment until now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jorgerobles Thanks for the PR! Do you still plan to work on this? In addition to the lint error, I would suggest you also add a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to fix it 🤦♂️
Great, thanks @jorgerobles ! Can you also add a test? It would be similar to the tests already existing: https://github.com/mozilla-services/react-jsonschema-form/blob/1941e760d8af93b118bbc193dd98b88f64b32645/test/StringField_test.js#L1503 |
@epicfaace I've added the test. I'm not very familiarised with mocha, hope is well. |
@jorgerobles Thanks, almost there -- instead of modifying the existing test, can you leave the existing test case "should reflect the change into the dom" in place and add a new test case right next to it? (you can copy and paste the existing test case and make the changes that you did) |
test/StringField_test.js
Outdated
@@ -1501,6 +1501,9 @@ describe("StringField", () => { | |||
describe("FileWidget", () => { | |||
const initialValue = "data:text/plain;name=file1.txt;base64,dGVzdDE="; | |||
|
|||
const nonUriEncodedValue = "fileáéí óú1.txt"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these two lines inside the "should encode file name with encodeURIComponent" test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you, @jorgerobles ! |
You're welcome :) it's a great project!
El dom., 20 ene. 2019 18:21, Ashwin Ramaswami <notifications@github.com>
escribió:
… Thank you, @jorgerobles <https://github.com/jorgerobles> !
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#967 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABoIYL_EZU2Hh0KIqwftS1_bNv6bI3_kks5vFKWqgaJpZM4U98M_>
.
|
@jorgerobles can you help with #824? It's pretty similar to this one. |
Reasons for making this change
Fix for non standard file names (with spaces, apostrophes, etc) that prevent to be used.
For example uploading a whitespace named file prevents to be used as background url.
Checklist
npm run cs-format
on my branch to conform my code to prettier coding style